package com.goodsogood.union.auth.sync;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.github.kevinsawicki.http.HttpRequest;
import com.goodsogood.union.auth.conf.CommonConfiger;
import com.goodsogood.union.auth.conf.LogConfiger;

/**
 * 修改手机号
 *
 * @author liuy
 */
@Component
public class UserPhoneUpdateSynchronizer {
    private final Logger logger = LoggerFactory.getLogger(LogConfiger.APP);
    private static final String editMobileUrl = CommonConfiger.getInstance().getHost() + "/union/syn/user/editMobile";
    public void excute(String userId, String mobilePhone) {
        try {
            new Thread(() -> {
                try {
                    String para = " {'userId':'" + userId + "','mobilePhone':'" + mobilePhone + "'}";
                    Map<String, String> params = new HashMap<>();
                    params.put("para", para);
                    
                    logger.info("sys.editMobile request is {}", params);
                    
                    String response = HttpRequest.post(
                            editMobileUrl
                            , params, true).body();
                    logger.info("sys.editMobile response is {}", response);
                } catch (Exception e) {
                    logger.error("sys.editMobile happen error , userId is {}, mobile is {}, error is ", userId, mobilePhone, e);
                }
            }).run();
        } catch(Exception e) {
            logger.error("UserPhoneUpdateSynchronizer happen error ", e);
        }
    }
}
